package xjtu.zd.server.normal.login.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import xjtu.zd.server.normal.login.LoginDto;
import xjtu.zd.server.normal.login.User;

public interface LoginDao {

    @Select("select u_id from t_user where (u_name=#{u_name} or u_email=#{u_email}) and u_pwd=#{u_pwd}")
    String findIdByPwd(LoginDto dto);

    @Select("select count(u_name) from t_user where u_name=#{u_name} or u_email=#{u_email}")
    int findCountByNameAndEmail(LoginDto dto);

    @Select("select u_id,u_name,u_email,u_pwd from t_user where u_email=#{u_email}")
    User findIdByEmail(LoginDto dto);

    @Insert("insert into t_user(u_id,u_name,u_pwd,u_email,u_time) values(#{u_id},#{u_name},#{u_pwd},#{u_email},#{u_time}) ")
    void insertUser(LoginDto dto);

    @Select("select lpad(ifnull(max(convert(substring(u_id,7,6),signed)),0)+1,6,'0')  from t_user where u_id like concat(#{date},'%')")
    String findNewUserId(String date);

    @Update("update t_user set u_pwd=#{u_pwd} where u_email=#{u_email}")
    void updatePwdByEmail(LoginDto dto);
}
